#include "types.h"



void Address::serialize(std::stringstream & ss)
{
	ip.serialize(ss);
	ss<<socet<<' ';
}

void Address::deSerialize(std::stringstream & ss)
{
	ip.deSerialize(ss);
	ss>>socet;
}


void String::serialize(std::stringstream & ss)
{
	
	ss<<str.size()<<' ';
	ss<<str<<' ';
}

void String::deSerialize(std::stringstream & ss)
{
	int size;
	ss>>size;
	str.clear();
	ss.get();
	for(int i =0; i <size;i++)
		str+=ss.get();
	char ch = ss.get();
}


void ServerInfo::serialize(std::stringstream & ss) 
{
	address.serialize(ss);
	name.serialize(ss);
	ss<<(int) serverStatus<<' ';

}

void ServerInfo::deSerialize(std::stringstream & ss) 
{
	address.deSerialize(ss);
	name.deSerialize(ss);
	int temp;
	ss>>temp;
	serverStatus = (SERVER_STATUS) temp;
}

void ServerFullInfo::serialize(std::stringstream & ss)
{
	ServerInfo::serialize(ss);
	ss << numberOfTasks<<' ';
}

void ServerFullInfo::deSerialize(std::stringstream & ss)
{
	ServerInfo::deSerialize(ss);
	ss>>numberOfTasks;
}

void CordinatorInfo::serialize(std::stringstream & ss)
{
	address.serialize(ss);
	serverName.serialize(ss);
}

void CordinatorInfo::deSerialize(std::stringstream & ss)
{
	address.deSerialize(ss);
	serverName.deSerialize(ss);
}

void TaskInfo::serialize(std::stringstream & ss)
{
	owner.serialize(ss);
	ss<<taskId<<' ';
	ss<< (int) taskStatus<<' ';
	result.serialize(ss);
}

void TaskInfo::deSerialize(std::stringstream & ss)
{
	owner.deSerialize(ss);
	ss>>taskId;
	int x;
	ss>>x;
	taskStatus = (TASK_STATUS) x;
	result.deSerialize(ss);

}


void Task::serialize(std::stringstream & ss)
{
	TaskInfo::serialize(ss);
	task.serialize(ss);
}

void Task::deSerialize(std::stringstream & ss)
{
	TaskInfo::deSerialize(ss);
	task.deSerialize(ss);

}

void Task::setTaskInfo(const TaskInfo& taskInfo)
{
	this->owner = taskInfo.owner;
	this->result = taskInfo.result;
	this->taskId = taskInfo.taskId;
	this->taskStatus = taskInfo.taskStatus;
}

TaskInfo Task::getTaskInfo() const
{
	TaskInfo taskInfo;
	taskInfo.owner = owner;
	taskInfo.result = result;
	taskInfo.taskId = taskId;
	taskInfo.taskStatus = taskStatus;
	return taskInfo;
}